<?php

class Df602_model extends Model {


    function Df602_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
	function truncateRealtime()
	{
		$this->db->delete('realtime');
	}
	
    function get_all_client_info()
    {
        $query = $this->db->get('client');
        return $query->result();
    }
	
	function remove_client($clientID)
	{
		$this->db->delete('client', array('id' => $clientID)); 
	}
	
	function insert_client_info($serverName, $hostName, $userName, $password)
	{
		$data = array(
			'name' 		=>	$serverName,
			'hostname'	=>	$hostName,
			'username'	=>	$userName,
			'password'	=>	$password
		);
		
		$this->db->insert('client', $data); 
	}
	
	function get_client_info($id)
	{
		$this->db->select('*');
		$this->db->from('client');
		$this->db->join('realtime', 'client.id = realtime.client_id');
		$this->db->where('client.id', $id); 
		$query = $this->db->get();
		//$query = $this->db->getwhere('client', array('id' => $id));
		return $query->result();
	}
	
	function get_client_name($id)
	{
		$cause = array('id'=>$id);
		$query = $this->db->getwhere('client', $cause);
        return $query->result();
	}

	function get_hd_info($clientID, $hdName)
	{
		$cause = array('Client_id'=>$clientID, 'device'=>$hdName);
		$query = $this->db->getwhere('realtime', $cause);
        return $query->result();
	}
	
    function get_history()
    {
        $query = $this->db->get('history');
        return $query->result();
    }

    function get_realtime()
    {
        $query = $this->db->get('realtime');
        return $query->result();
    }


}



?>